package com.glq.book.service;

import com.glq.book.dao.BookDao;
import com.glq.book.entity.Book;
import com.glq.book.vo.BookVO;

public class BookService {

    private BookDao bookDao = new BookDao();

    /**
     * 成功返回 true
     * 失败返回 false
     * 添加书籍
     *
     * @param bookName
     * @param bookPrice
     * @param bookNumber
     * @param bookType
     * @param bookFengMian
     * @param bookType
     * @param bookFengMian
     * @return
     */
    public boolean insertBook(String bookName, Integer bookPrice, Integer bookNumber, String bookType, String bookFengMian, String bookAuthor, String bookAbstract) {
        BookVO book = new BookVO(bookName, bookPrice, bookNumber, bookType,bookFengMian,bookAuthor,bookAbstract);
        if (book.getBookPrice() < 0 || book.getBookNumber() < 0) {
            return false;
        }
        return !bookDao.insertBook(book);
    }

    /**
     * 下架书籍
     *
     * @param id
     * @return
     */
    public boolean deleteBook(Integer id) {
        if (id < 0) {
            return false;
        }
        return !bookDao.deleteBook(id);
    }

    /**
     * 更新书籍
     *
     * @param bookPrice
     * @param id
     * @param bookFengMian
     * @param bookName
     * @param bookType
     * @param bookAuthor
     * @param bookFengMian
     * @return
     */
    public boolean updateBook(Integer bookPrice,
                              Integer id,
                              String bookFengMian,
                              String bookName,
                              String bookType,
                              String bookAuthor,
                              String bookAbstract ,
                              Integer bookNumber) {
        if (bookPrice < 0) {
            return false;
        }
        return !bookDao.updateBook(bookPrice, id,bookFengMian,bookName,bookType,bookAuthor,bookAbstract,bookNumber);
    }
}
